package baiwa.rta.dao.mapping;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowMapper;

import baiwa.rta.model.RMsreqhdr;
import baiwa.rta.model.TowerModel;
import baiwa.rta.utils.DateUtils;


public class RequestMapping implements RowMapper<RMsreqhdr> {

    public RMsreqhdr mapRow(ResultSet rs, int line) throws SQLException {
        ResultSetExtractor<RMsreqhdr> extractor = new ResultSetExtractor<RMsreqhdr>() {
            public RMsreqhdr extractData(ResultSet rs) throws SQLException, DataAccessException {
                RMsreqhdr model = new RMsreqhdr();
                model.setSreqhid(rs.getInt("SREQHID"));
                model.setSreqhdocno(rs.getString("SREQHDOCNO"));
                model.setSreqhstat(rs.getString("SREQHSTAT"));
                model.setSreqhprt(rs.getString("SREQHPRT"));
                model.setSreqhreqby(rs.getString("SREQHREQBY"));
                model.setSreqhreqdat(rs.getDate("SREQHREQDAT"));
                model.setSreqhtel(rs.getString("SREQHTEL"));
                model.setSreqhdesc(rs.getString("SREQHDESC"));
                model.setSreqhlht(rs.getString("SREQHLHT"));
                model.setSreqhtelele(rs.getString("SREQHTELELE"));
                model.setSreqhaircon(rs.getString("SREQHAIRCON"));
                model.setSreqhstr(rs.getString("SREQHSTR"));
                model.setSreqhapl(rs.getString("SREQHAPL"));
                model.setSreqhpool(rs.getString("SREQHPOOL"));
                model.setSreqhcln(rs.getString("SREQHCLN"));
                model.setSreqhscr(rs.getString("SREQHSCR"));
                model.setSreqhconnm(rs.getString("SREQHCONNM"));
                model.setSreqhasto(rs.getString("SREQHASTO"));
                model.setSreqhresdat(rs.getDate("SREQHRESDAT"));
                model.setSreqhrestm(rs.getString("SREQHRESTM"));
                model.setSreqhcus(rs.getString("SREQHCUS"));
                model.setSreqhsptm(rs.getString("SREQHSPTM"));
                model.setSreqhwttm(rs.getString("SREQHWTTM"));
                model.setSreqhcuswttm(rs.getString("SREQHCUSWTTM"));
                model.setRlrmid(rs.getInt("RLRMID"));
                model.setSreqhcreby(rs.getString("SREQHCREBY"));
                model.setSreqhcredat(rs.getDate("SREQHCREDAT"));
                model.setSreqhupdby(rs.getString("SREQHUPDBY"));
                model.setSreqhupddat(rs.getDate("SREQHUPDDAT"));
                model.setSreqhspdat(rs.getDate("SREQHSPDAT"));
                model.setSreqhwtdat(rs.getDate("SREQHWTDAT"));
                model.setSreqcptdate(rs.getDate("SREQCPTDATE"));
                model.setSreqcpttm(rs.getString("SREQCPTTM"));
                
                /* ---- Tower Data From Join Table------*/
                TowerModel tower = new TowerModel();
                tower.setTower(rs.getString("RLSTTOWER"));
                tower.setFloor(rs.getString("RLSTFLOOR"));
                tower.setUnitNo(rs.getString("RLSTUNITNO"));
                tower.setAddress(rs.getString("RLSTADDR"));
                model.setTowerModel(tower);
                
                return model;
            }
        };
        return extractor.extractData(rs);
    }
}
